﻿using System;
using System.Buffers;
using Microsoft.Extensions.Logging;
using SuperSocket.ProtoBase;

namespace MSocketCore.MSocket
{
    public class MyPackageDecoder : IPackageDecoder<MyPackage>
    {
        private readonly ILogger<MyPackageDecoder> _logger;

        public MyPackageDecoder(ILogger<MyPackageDecoder> logger)
        {
            _logger = logger;
        }
        public MyPackage Decode(ref ReadOnlySequence<byte> buffer, object context)
        {
            var package = new MyPackage();
            //var reader = new SequenceReader<byte>(buffer);
            _logger.LogInformation($"Message ：{BitConverter.ToString(buffer.ToArray()).Replace("-", " ")}");
            //var pack = reader.Sequence.Slice(0);
           var info = package.Prase(buffer.ToArray());
            if (info == null)
            {
                package.Key = "EE";
                package.Sn = "";
                return package;
            }
            return package;
        }
    }
}
